function getDimensionValues(url){

var ajax_load = "<img class='loading' src='./views/images/loading.gif'  alt='loading...' />";
$('#dimensionvalue').html(ajax_load);


var param=getParameters(url.toString());

$.ajax({
    url: './index.php',
    type: 'POST',
	data:"uri="+param[0]+"&endpoint="+param[1]+"&rt=dimension/view",
    timeout: 1000,
	dataType:"json",
    error: function(err){
        alert('No Dimension exists...error');
    },
    success: function(responseText){
   
	if(responseText.status==="ok"){
     fillInterfaceWithJsonObjectOfDimension(responseText.dimension,responseText.values,responseText.numbers,param);
	}
	else
	{
      alert('No Dimension exists...');
	}
    }
});

}

function fillInterfaceWithJsonObjectOfDimension(dimension,values,numbers,param){

$('#dimensionvalue').html("");
	 var table=$(document.createElement('table')).attr('text-align','center').width('100%');
	 var tr=$(document.createElement('tr')).hover(function ()
			{ $(this).addClass("hover");},  function () {$(this).removeClass("hover");});;
     var td1=$(document.createElement('td'))
		 .addClass('title');
     td1.append("<span>"+dimension.label+" Dimension</span>");
	 tr.append(td1);
     var tr2=$(document.createElement('tr')).width('100%').hover(function ()
			{ $(this).addClass("hover");},  function () {$(this).removeClass("hover");});
	 var td2=$(document.createElement('td'))
		 .addClass('uri').html('URI (if de-referancable)');
	 var anchor=$(document.createElement('a'))
		 .attr('href',dimension.URI);
	 var img=$(document.createElement('img'))
		 .attr('src','./views/images/external_link_icon.gif');
     anchor.append(img);
     td2.append(anchor);
	 tr2.append(td2);
     var tr3=$(document.createElement('tr')).width('100%').hover(function ()
			{ $(this).addClass("hover");},  function () {$(this).removeClass("hover");});
	 var td3=$(document.createElement('td'))
		 .addClass('comment').html(dimension.comment);
	 tr3.append(td3);
     

	 var tr4=$(document.createElement('tr')).width('100%').hover(function ()
			{ $(this).addClass("hover");},  function () {$(this).removeClass("hover");});;
	 var td4=$(document.createElement('td')).html('<strong>Dimension Values :</strong>');
	 var ul1=$("#valcloud").addClass('valuecloud');
     
     for(i=0;i<values.length;i++){
	  var li=$(document.createElement('li'));
	  var anchor2=$(document.createElement('a')).html(values[i].value).bind('click',{dimension:dimension.URI,uri:values[i].valueURI,endpoint:param[1]},function(event){
	  //showDimension(event.data.dimension,event.data.uri,event.data.endpoint);
	  } );
      li.append(anchor2);
	  
	  li.attr('value',numbers[i]);
	  ul1.append(li);
	 }
     //var tr5=$(document.createElement('tr')).width('100%');
	 //var td5=$(document.createElement('td'));
	 //var divob=$(document.createElement('div')).attr('id','obser').height(400);
	  //$("#valcloud").tsort({order:"rand"});
	 
	// $("#valcloud").tagcloud({type:"sphere",sizemin:20,power:.3,height:100});

	 //tr5.append(td5);
	
	 tr4.append(td4);
	 table.append(tr);
     
	 table.append(tr2);
	 table.append(tr3);
     table.append(tr4);
	 //table.append(tr5);
	$('#dimensionvalue').append(table);

}
function showDimension(dimension,uri,endpoint)
{

$.ajax({
    url: './index.php',
    type: 'POST',
	data:"uri="+uri+"&dimension="+dimension+"&endpoint="+endpoint+"&rt=dimension/valueobervation",
    timeout: 1000,
	dataType:"json",
    error: function(err){
        alert('No Observations exist...error');
    },
    success: function(responseText){
    
	if(responseText.status==="ok"){
     fillInterfaceWithJsonRelatedOberservation(responseText.observations,endpoint);
	}
	else
	{
      alert('No Observations exist...');
	}
    }
});

}

function fillInterfaceWithJsonRelatedOberservation(observations,endpoint){

$('#obser').html("");
//var table=$(document.createElement('table')).attr('text-align','center').width('100%');
for(i=0;i<observations.length;i++){
 
 //var tr=$(document.createElement('tr'));
 //var td=$(document.createElement('td')).hover(function ()
		//	{ $(this).addClass("hover");},  function () {$(this).removeClass("hover");});
 var anchor=$(document.createElement('a'))
		 .attr('href','./index.php?uri='+observations[i]+'&endpoint='+endpoint).html('Observation'+i);
  //tr.append(td);
  //table.append(tr);
  $('#obser').append(anchor).append('<br/>');		 
}
//$('#obser').add(table);		 
}
function getParameters(url){
var arr=new Array();
 var split1=url.split('?');
 var split2=split1[1].split('&');
 for(i=0;i<split2.length;i++){
    var split3=split2[i].split('=');
	if(split3[0]=="uri"){
	  arr[0]=split3[1];
	}
	if(split3[0]=="endpoint"){
	  arr[1]=split3[1];
	}
	if(split3[0]=="rt"){
	  arr[2]=split3[1];
	}
 }

return arr;
}
